package com.solocredit.finance.ui.user.impl

import com.solocredit.finance.data.analyse.util.GoogleUtil
import com.solocredit.finance.http.ApiService
import com.solocredit.finance.http.ApiService.addCommonParams
import com.solocredit.finance.http.ApiService.addRandomParams
import com.solocredit.finance.http.HttpHelper
import com.solocredit.finance.http.IHttpCallback
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/26 16:26
 * @Annotation：用户登录 Model 实现
 */
class MullaLoginModelImpl {

    /**
     * 发送验证码
     */
    fun sendMullaMsgCodeAction(mobile: String?, callBack: IHttpCallback) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_PATH.MULLA_API_SEND_MSG_PATH)
        val params = JSONObject()
            .addCommonParams()//通用参数
            .addRandomParams()//随机参数
            .apply {
                put("mobile",mobile)
            }
        HttpHelper.postMullaAction(httpUrl,params,callBack)
    }

    /**
     * 登录
     */
    fun loginMullaAction(mobile: String, code: String, directLoginFlag: String,loginParam: String, callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_PATH.MULLA_API_LOGIN_PATH)
        val params = JSONObject()
            .addCommonParams()
            .addRandomParams()
            .apply {
                put("mobile",mobile)//手机号
                put("code",code)//验证码
                put("channelCode", GoogleUtil.getInstallReferrer())//渠道号
                put("subChannelCode", GoogleUtil.getInstallReferrer())//子渠道号
                put("directLoginFlag",directLoginFlag)//是否直接登录
                put("notBindWalletFlag","YES")//不自动绑卡
                put("loginParam",loginParam)
            }
        HttpHelper.postMullaAction(httpUrl,params,callBack)
    }

    /**
     * 无验证码登录
     */
    fun loginMullaNoCodeAction(mobile: String,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_PATH.MULLA_API_LOGIN_NO_CODE_PATH)
        val params = JSONObject()
            .addCommonParams()
            .addRandomParams()
            .apply {
                put("mobile",mobile)//手机号
                put("code","0000")//验证码
                put("channelCode", GoogleUtil.getInstallReferrer())//渠道号
                put("subChannelCode", GoogleUtil.getInstallReferrer())//子渠道号
                put("directLoginFlag","YES")//是否直接登录
                put("notBindWalletFlag","YES")//不自动绑卡
                put("loginParam","")
            }
        HttpHelper.postMullaAction(httpUrl,params,callBack)
    }
}